﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using School.Entities;

namespace School.Service.Uniform
{
    public static class SRV_Clothe_Price
    {
        private static SchoolEntities db = new SchoolEntities();
        public static IEnumerable<School.Entities.SRV_Clothe_Price> AllClothePrices()
        {
            var query = from price in db.SRV_Clothe_Price select price;
            return query.ToList();
        }
        public static IEnumerable<object> GetPricesByClothe_Id(long id)
        {
            var query = from price in db.SRV_Clothe_Price
                        where price.SRV_Clothe_Sizes.SRV_Clothe.Id == id
                        orderby price.DateTime 
                        select new
                        {
                            Id = price.Price_Id,
                            Code = price.SRV_Clothe_Sizes.SRV_Clothe.Code,
                            Descrption = price.SRV_Clothe_Sizes.SRV_Clothe.Description,
                            SizeName = price.SRV_Clothe_Sizes.Name,
                            price = price.Price,
                            Size_Id = price.SRV_Clothe_Sizes.Size_Id
                        };
            return query.ToList();
        }
        public static bool InsertClothe_Price(School.Entities.SRV_Clothe_Price ClothePrice)
        {
            db.AddToSRV_Clothe_Price(ClothePrice);
            try
            {
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool InsertClothe_Price(List<School.Entities.SRV_Clothe_Price> ClothePrices)
        {
            foreach (School.Entities.SRV_Clothe_Price item in ClothePrices)
            {
                db.AddToSRV_Clothe_Price(new School.Entities.SRV_Clothe_Price() { 
                Price = item.Price,
                Size_Id = item.Size_Id,
                DateTime = item.DateTime
                });
            }
            try
            {
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
